//
// Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
//
// GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
//  Author: Shawn.Tan
//  Date : 2025.10.28
//
//  History : Initial Version 2025.10.28
//

//
#ifndef Green_GeneratorGPGPU_H
#define Green_GeneratorGPGPU_H

#include "Generator.h"

namespace Green {

  class RegisterField;

  /*!
    \class GeneratorGPGPU
    \brief Base generator class for GPGPU 64-bit architecture.
  */
  class GeneratorGPGPU : public Generator {
  public:
    GeneratorGPGPU() : Generator(-1ull), mpPrivilegeField(nullptr), mThroughputEngineID(0), mThroughputCoreID(0), mArrayID(0) { } //!< Constructor.
    GeneratorGPGPU(const GeneratorGPGPU& rOther) : Generator(rOther), mpPrivilegeField(nullptr), mThroughputEngineID(0), mThroughputCoreID(0), mArrayID(0){ } //!< Copy constructor.
    ~GeneratorGPGPU(); //!< Destructor.
    ASSIGNMENT_OPERATOR_ABSENT(GeneratorGPGPU);

    Object* Clone() const override; //!< Clone a object of the GeneratorGPGPU type.
    const char* Type() const override { return "GeneratorGPGPU"; }

    void Setup(uint32 threadId) override; //!< Setup GPGPU generator.
    uint32 InstructionSpace() const override; //!< Return necessary space between instruction streams for GPGPU.
    uint32 BntReserveSpace() const override; //!< Return the number of memory bytes to reserve for a BNT path.
    uint32 BntMinSpace() const override; //!< Return the minimum number of memory bytes to generate a BNT path.
    void SetPrivilegeLevel(uint32 priv) override; //!< Set GPGPU exception level.
    uint32 PrivilegeLevel() const override; //!< Return GPGPU exception level
    ConditionFlags GetConditionFlags() const override; //!< Return current condition flag values.
    std::string GetGPRName(uint32 index) const override; //!< Return GPR name from index value
    std::string GetGPRExcludes() const override; //!< Return gpr exclude indices in string format
    bool RegisterUpdateSystem(const std::string& name, const std::string& field) override;
    void UpdateSystemWithRegister(const std::string& name, const std::string& field, uint64 value) override; //!< API that checks and update system according to given register name, field, and value
    void SetupInstructionGroup(EInstructionGroupType iGrpType) override; //!< Setup necessary resources for instruction group.
    bool OperandTypeCompatible(ERegisterType regType, EOperandType oprType) const override; //!< Check if the operand type is compatible with the register type.
    bool OperandTypeToResourceType(EOperandType opType, EResourceType& rResType) const override; //!< Convert operand type to resource type.
    uint32 GetResourceCount(EResourceType rResType) const override; //!< Return resource count for a certain resource type.
    void AdvancePC() override; //!< Advance Generator PC by default value.
    void UpdateGPGPUID();
  protected:
    void AddArchImageThreadInfo(std::map<std::string, uint64>& rThreadInfo) const override; //!< Add architectural specific image thread info.
  protected:
    RegisterField* mpPrivilegeField; //!<Privilege level internal register field pointer
    uint32_t mThroughputEngineID; // the TE ID for current ISG physical thread
    uint32_t mThroughputCoreID;  //  the TC ID for current ISG physical thread
    uint32_t mArrayID;   // the Array ID for current ISG physical thread
  };

}

#endif
